﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DevExpress.Xpo;
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Editors;
using DevExpress.ExpressApp.Model;
using DevExpress.ExpressApp.Win.Editors;
using DevExpress.Persistent.Base;

namespace WinSCM.Module.UserControls
{
    public class NavImageProperty
    {

    }

    public class NavImageObject : XPLiteObject
    {
        public NavImageObject(Session session)
            : base(session)
        {

        }
        private string _EditorObjectType;
        [Custom("Caption", "EditorObjectType")]
        [Key(false)]
        public string EditorObjectType
        {
            get { return _EditorObjectType; }
            set { SetPropertyValue<string>("EditorObjectType", ref _EditorObjectType, value); }
        }

        [NonPersistent]
        public NavImageProperty Editor
        {
            get { return null; }
        }
    }
    public interface INavImageUserControl
    {
        XafApplication XafApplication { get; set; }
    }
    [PropertyEditor(typeof(NavImageProperty), true)]
    public class MenuPropertyEditor : WinPropertyEditor, IComplexPropertyEditor
    {
        public MenuPropertyEditor(Type objectType, IModelMemberViewItem model)
            : base(objectType, model)
        {

        }
        private XafApplication helper;
        protected override object CreateControlCore()
        {
            NavImageObject o = CurrentObject as NavImageObject;
            INavImageUserControl inavImageUser = ReflectionHelper.CreateObject(o.EditorObjectType) as INavImageUserControl;
            inavImageUser.XafApplication = helper;
            return inavImageUser;
        }

        public void Setup(IObjectSpace objectSpace, XafApplication application)
        {
            if (helper == null)
            {
                helper = application;
            }
        }
    }
}
